package hu.u_szeged.inf.ovrt.filelister.core.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * Parameter builder implementation.
 */
public class SimpleParameterBuilder implements ParameterBuilder {

    private static final Pattern PATTERN = Pattern.compile("-\\S");

    @Override
    public Map<String, String> getParameterMap(String parameterString) {

        Map<String, String> parameters = new HashMap<String, String>();

        int index = parameterString.indexOf('-');

        if (PATTERN.matcher(parameterString).find()
                && parameterString.length() == 2
                && ("l".equals(parameterString.substring(1)) || "c".equals(parameterString.substring(1))
                || "d".equals(parameterString.substring(1)) || "f".equals(parameterString.substring(1)))) {
            String parameter = parameterString.substring(index + 1, index + 2);
            parameters.put(parameter, parameter);
        } else {
            parameters.put("default", parameterString);
        }

        return parameters;
    }
}
